# -*- coding: utf-8 -*-

import glob
import string
import re
import d15n_routines as r
from salt_file import salt

n = '\x0D\x0A'

if 1: # calculate sha256 digests
    
    for f in glob.glob('_cleanup_POC_ID_email_decline_v3.csv'):

        i = open(f, 'r')
        o = open('_d15n_final' + f, 'wb')
        o.write('ID\tMA_Email_alias_d15n\tMA_Email_domain' + n)

        for l in i.readlines():
        
            l = r.remove_eol(l)
        
            id, em, em_alias, em_domain = string.split(l, '\t')

            if em_alias <> '': 
                em_alias = r.sha256(em_alias + salt)
            else:
                em_alias = ''

            #test run
            #res = "%s\t%s\t%s\t%s\t%s" % (l, id, em, em_alias, em_domain) + n
            #final run ... original line (l) ommited
            res = "%s\t%s\t%s" % (id, em_alias, em_domain) + n

            o.write(res)
        o.close()
